﻿using System;
using System.Windows.Forms;

namespace UsercontrolDatalinkage
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void icon1_Click(object sender, EventArgs e)
        {
            var panel = new ControlPanel(icon1);
            icon1.PVChanged += panel.SetPV;
            icon1.MVChanged += panel.SetMV;
            panel.Disposed += (obj, eve) =>
            {
                icon1.PVChanged -= panel.SetPV;
                icon1.MVChanged -= panel.SetMV;
            };
            panel.Show();
        }

        private void textBox1_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                int pvVal;
                if (int.TryParse(textBox1.Text, out pvVal))
                {
                    icon1.PV = pvVal;
                }
                else
                {
                    MessageBox.Show("请输入整数", "提示");
                    textBox1.Text = "";
                }
            }
        }
    }
}
